// fn main() {
//     let some_op: Option<i32> = None;
//     if let Some(x) = some_op {
//         println!("{}", x);
//     }
//     if let x=5 {
//         println!("{}", x);
//     }
// }

//匹配字面量
// fn main() {
//     let x = 1;
//     match x {
//         1 => println!("one"),
//         2 => println!("two"),
//         3 => println!("three"),
//         _ => println!("anything"),
//     }
// }
// 输出 one

// 匹配命名变量
// fn main() {
//     let x = Some(5);
//     let y = 10;
//     match x {
//         Some(50) => println!("Got 50"),
//         Some(y) => println!("Matched, y = {y}"), //匹配任意值,
//         _ => println!("Default case, x = {:?}", x),
//     }
//     println!("at the end: x = {:?}, y = {y}", x); //10,5
// }

//多个模式
// fn main() {
//     let x = 2;
//     match x {
//         1 | 2 => println!("one or two"), // | 或匹配多个
//         3 => println!("three"),
//         _ => println!("anything"),
//     }
// }

// 通过 ..= 匹配值的范围,只允许数字或char
fn main() {
    let x = 5;

    match x {
        1..=5 => println!("one through five"),
        _ => println!("something else"),
    }

    let y = 'c';

    match y {
        'a'..='j' => println!("early ASCII letter"),
        'k'..='z' => println!("late ASCII letter"),
        _ => println!("something else"),
    }
}
